package com.suian.spring.aop.test;

import com.suian.spring.aop.JdkAopProxy;
import com.suian.spring.aop.MethodInterceptor;
import com.suian.spring.aop.interceptor.LogInterceptor;
import com.suian.spring.aop.interceptor.PerformanceInterceptor;

import java.util.ArrayList;

public class UserServiceImpl implements UserService {
    @Override
    public void createUser(String name) {
        System.out.println("Creating user: " + name);
    }

    @Override
    public String getUser(int id) {
        return "User-" + id;
    }

    public static void main(String[] args) {
        //原始对象
        UserService target = new UserServiceImpl();

        //创建拦截器链
        ArrayList<MethodInterceptor> interceptors = new ArrayList<>();
        interceptors.add(new LogInterceptor());
        interceptors.add(new PerformanceInterceptor());



        //生成代理对象
        UserService proxy = (UserService) JdkAopProxy.createProxy(target, interceptors);

        //调用方法
        proxy.createUser("adv");
//        System.out.println(proxy.getUser(222));

    }
}
